import time
import calendar
import datetime

# time使用
# 本地时间，未格式化
localtime = time.localtime(time.time())
print(localtime)
# 格式化后的时间
localtime = time.asctime(localtime)
print(localtime)
# 格式化yyyy-MM-dd HH:mm:ss
localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(localtime)
print(time.clock())

# calendar的使用
# 打印日历
cal = calendar.month(2016, 1)
print(cal)
# 每周起始日期
print(calendar.firstweekday())

# datetime的使用
print(datetime.date.today())


# 函数的使用
def testOne(str):
    '打印任何传入的字符串'
    for index in range(3):
        print(str)
    return str


testOne("123")

# 匿名函数
sum = lambda v1, v2: v1 + v2
print(sum(3, 4))

# 全局变量
gv = 2000;
def testTwo():
    a = 3
    global gv
    gv += 1
    print(globals())
    print(locals())
    return gv
print(gv, end=" ")
print(testTwo())

for x, y in [(1, '2'), ('3', 4)]:
    print(x, y)

# 迭代dic
va = {1: 3, 3: 2, 4: 3}
for v, y in va.items():
    print(v, y)
# method2
def recycle():
    testDic = [x + y for x, y in va.items()]
    for v in range(len(testDic)):
        print(testDic[v])
    return
recycle()
#将函数赋值给变量
f=recycle
print(f.__name__)
print(recycle.__name__)